package com.cloudspace.yunloan.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.cloudspace.yunloan.R;
import com.cloudspace.yunloan.manager.HeadphotoManager;
import com.cloudspace.yunloan.net.manager.ImageManager;

import java.io.File;

/**
 * Created by xianh on 2017/6/17.
 */

public class ImagePickActivity extends YunloanActivity {
    private Button registerBtn;
    private ImageView chooseImg;

    private HeadphotoManager headphotoManager;

    private View.OnClickListener registerListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            headphotoManager.showChangeHeadPhotoDialog();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_picture_choose);

        registerBtn = (Button) findViewById(R.id.register);
        registerBtn.setOnClickListener(registerListener);

        chooseImg = (ImageView) findViewById(R.id.choose_img);

        headphotoManager = new HeadphotoManager(this);
        headphotoManager.setOnHeadphotoCropListener(new HeadphotoManager.OnHeadphotoCropListener() {
            @Override
            public void headphotoCroped(File file) {
                ImageManager.loadCircleImage(ImagePickActivity.this, chooseImg, file);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        super.onActivityResult(requestCode, resultCode, data);
        headphotoManager.onActivityResult(requestCode, resultCode, data);
    }

    public static void showActivity(Context context){
        Intent intent = new Intent(context, ImagePickActivity.class);

        if (!(context instanceof Activity)){
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }

        context.startActivity(intent);
    }
}
